package com.wukong.logisticsproject.controller;


import com.wukong.logisticsproject.ex.ParameterValidationException;
import com.wukong.logisticsproject.model.Problem;
import com.wukong.logisticsproject.model.Staff;
import com.wukong.logisticsproject.model.VerifySeq;
import com.wukong.logisticsproject.service.IProblemService;
import com.wukong.logisticsproject.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 问题件表 前端控制器
 * </p>
 *
 * @author wukong.com
 * @since 2020-10-08
 */
@RestController
@Slf4j
public class ProblemController {

    @Autowired
    private IProblemService iProblemService;

    //修改数据
    @ResponseBody
    @RequestMapping(value = "/addProblem", method = {RequestMethod.POST})
    public R addProblem(@Validated(VerifySeq.class) Problem problem, BindingResult bindingResult) {
        System.err.println("接收的数据-->" + problem);

        if (bindingResult.hasErrors()) {
            String errorMessage = bindingResult.getFieldError().getDefaultMessage();
            log.debug("验证参数格式失败！{}", errorMessage);
            throw new ParameterValidationException(errorMessage);
        }

        return R.ok(iProblemService.addProblem(problem));

    }

}
